#include "dag_nodes.h"
#include "dag_operators.h"

using namespace dag;
using namespace std;

namespace {
	NodeTraits n_traits;
}

NearestNeighborNode::NearestNeighborNode(const FrameSpec& outputSpec)
:	m_OutputSpec(outputSpec),
	m_InputSpec(FrameSpec()),
	m_InputDepot(NULL),
	m_OutputDepot(NULL)
{
	n_traits.canReverse = false;
	n_traits.resources = LearnResource_InputsOutputs;
}

NearestNeighborNode::~NearestNeighborNode() throw() {
}

const NodeTraits& NearestNeighborNode::traits() const {
	return n_traits;
}
	
void NearestNeighborNode::_init(const FrameSpec& expectedInputSpec) {
	m_InputSpec = expectedInputSpec;
}

const FrameSpec& NearestNeighborNode::_inputSpec() const {
	return m_InputSpec;
}

const FrameSpec& NearestNeighborNode::_outputSpec() const {
	return m_OutputSpec;
}

auto_ptr<FrameOperator> NearestNeighborNode::_createForwardOp() const {
	return auto_ptr<FrameOperator> (new KdTreeOp(*m_InputDepot,
												 *m_OutputDepot));
}

void NearestNeighborNode::_learn(const FrameDepot* input, 
								 const FrameDepot* output) {
	updateLearnProgress("copying inputs", 0);
	m_InputDepot.reset(new FrameDepot(*input));
	updateLearnProgress("copying outputs", 0.5);
	m_OutputDepot.reset(new FrameDepot(*output));
}

